import java.util.Scanner;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/20 16:34
 */
public class TestRadix {
    public static String jinZhiZhuanHuan(String num,int n,int b) {
        String a = num;
        int s = Integer.parseInt(a, n);
        String ret = Integer.toString(s, b);
        return ret;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String num=scan.next();
        int n = scan.nextInt();
        int b=scan.nextInt();
        String ret=jinZhiZhuanHuan(num,n,b);
        System.out.println(ret);

    }
}
